<template>
  <div>
    <zbTable ref="tableRef" :api-fun="get_list" @action="action">
      <template #toolbar>
        <a-space>
          <a-button type="dashed" class="ele-btn-icon" @click="daochu()">
            <template #icon>
              <upload-outlined />
            </template>
            <span>导出</span>
          </a-button>
        </a-space>
      </template>
    </zbTable>
    <!-- 拒绝弹窗 -->
    <check-data
      v-if="showCheck"
      v-model:visible="showCheck"
      :code="code"
      @done="done"
    />
  </div>
</template>

<script setup>
  import { ref } from 'vue';
  import { message, Modal } from 'ant-design-vue';
  import { actionFn } from '@/utils/action.js';
  import { daochuFn } from '@/utils/daochu.js';
  import { PlusOutlined, UploadOutlined } from '@ant-design/icons-vue';
  import zbTable from '@/components/zbTable/jewelryEnterIndex.vue';
  import checkData from './components/check-data.vue';
  import { get_list, confirm_receive } from '@/api/jewelry/receipts_enter';

  const tableRef = ref(null);
  const showCheck = ref(false);
  const code = ref(null);
  const actionData = ref({});

  const action = (data) => {
    code.value = data.row_data.code;
    actionData.value = data.action_data;
    if (data.action_data.type == 'agree') {
      Modal.confirm({
        title: '提示',
        content: '确认接收?',
        maskClosable: true,
        onOk: () => {
          receive(data);
        }
      });
    } else if (data.action_data.type == 'reject') {
      showCheck.value = true;
    }
  };
  const receive = (data) => {
    confirm_receive({
      code: data.row_data.code,
      receive_status: 1,
      receive_cause: ''
    })
      .then((res) => {
        reloadTable();
        message.success(res.msg);
      })
      .catch((e) => {
        message.error(e);
      });
  };
  const done = (form) => {
    actionFn(actionData.value, form, reloadTable);
  };
  const reloadTable = () => {
    showCheck.value = false;
    tableRef.value.reload();
  };
  const daochu = ()=>{
    let data = {
  	  url:'jewelry/receipts_enter/export',
  	  params:{},
  	  filename:'首饰调拨入库列表'
    }
    daochuFn(data);
  };
</script>
